"""
@FileName：3死锁.py
@Author：lmz
@Time：2021/5/20 23:00
"""
import threading
import time

lockA=threading.Lock()
lockB=threading.Lock()
a,b=1,1
def func_1():
    global a,b
    lockA.acquire()
    time.sleep(0.01)
    a += 1
    print('in func_1, a is %d.\n'%(a))
    lockB.acquire()
    b += 1
    print('in func_1, b is %d.\n'%(b))
    lockB.release()
    lockA.release()

def func_2():
    global a,b
    lockB.acquire()
    b -= 1
    print('in func_2, b is %d.\n'%(b))
    lockA.acquire()
    a -= 1
    print('in func_2, a is %d.\n'%(a))
    lockB.release()
    lockA.release()

t1=threading.Thread(target=func_1,args=())
t2=threading.Thread(target=func_2,args=())
t1.start()
t2.start()